﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PerfumeShopManagement.Model;
using PerfumeShopManagement.DAL;
using PerfumeShopManagement.Utility;

namespace PerfumeShopManagement.BLL
{
    public class BllRepositoryHistory : BllAbstractBase<RepositoryHistory, string>
    {
        public BllRepositoryHistory() 
            : base()
        {
            items = DalFactory.RepositoryHistoryDAL.GetAllObjects();
        }

        public override List<RepositoryHistory> GetAll()
        {
            throw new NotImplementedException();
        }

        public override RepositoryHistory Get(string id)
        {
            throw new NotImplementedException();
        }

        public override List<RepositoryHistory> Search(RepositoryHistory criteria)
        {
            throw new NotImplementedException();
        }

        public override bool Save(RepositoryHistory obj)
        {
            throw new NotImplementedException();
        }

        public override bool DeleteById(string id)
        {
            throw new NotImplementedException();
        }

        public int GetInventoryOfDay(DateTime date, int productId)
        {
            int inventory = 0;

            DateTime tempDate = new DateTime(date.Year, date.Month, date.Day, 23, 59, 59);
            foreach (RepositoryHistory item in items)
            {
                if (item.ProductId == productId && item.ActiveTime.Date.CompareTo(tempDate) < 0)
                {
                    if (Constants.INITIAL_KIND == item.ActivityKind)
                    {
                        inventory = item.Value;
                    }
                    else if (Constants.IMPORT_KIND == item.ActivityKind)
                    {
                        inventory += item.Value;
                    }
                    else if (Constants.EXPORT_KIND == item.ActivityKind)
                    {
                        inventory -= item.Value;
                    }
                }
            }

            return inventory;
        }
    }
}
